package cn.tedu.dimanage.message.webapi.controller;


import cn.tedu.dimanage.common.web.JsonResult;
import cn.tedu.dimanage.message.service.IMessageService;
import cn.tedu.dimanage.pojo.dto.MessageDTO;
import cn.tedu.dimanage.pojo.vo.MessageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
@RequestMapping("/message")
@Slf4j
public class MessageController {



    @Autowired
    private IMessageService messageService;

    //这个是创建父类评论
    @RequestMapping("/add-MessageParent")
    public JsonResult<Void> addMessageParent(MessageDTO messageDTO){

        messageService.addMessageParent(messageDTO);
        return JsonResult.ok();

    }

    //这是创建子集评论
    @RequestMapping("/add-MessageSubset")
    public JsonResult<Void> addMessageSubset(MessageDTO messageDTO){
        messageService.addMessageSubset(messageDTO);
        return JsonResult.ok();
    }

    //删除评论 顶级或子集都可以
    @RequestMapping("/deleteMessage")
    public JsonResult<Void> deleteMessage(Long id){
        messageService.deleteMessage(id);
        return JsonResult.ok();
    }

    //显示所有的父级id对象
    @GetMapping("/select")
    public JsonResult<List<MessageVO>> selectList(){
        List<MessageVO> messageVOList = messageService.selectList();

        return JsonResult.ok(messageVOList);
    }

    //显示对应的父级id下所有的子集对象
    @GetMapping("/selectSubset")
    public JsonResult<List<MessageVO>> selectSubset(Long id){
        List<MessageVO> messageSubsetList = messageService.selectSubsetList(id);
        return JsonResult.ok(messageSubsetList);
    }

}
